package com.eairlv.route.client.core;

import com.eairlv.route.client.service.RouteLoadService;
import feign.InvocationHandlerFactory;
import feign.Target;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @author eairlv
 * @description
 * @date 11:19 2019/12/9
 */
@Slf4j
public class RouteInvocationHandlerFactory implements InvocationHandlerFactory {

    private RouteLoadService routeLoadService;

    public RouteInvocationHandlerFactory(RouteLoadService routeLoadService) {
        this.routeLoadService = routeLoadService;
    }

    /**
     * 重写方法
     * @param target
     * @param dispatch
     * @return
     */
    @Override
    public InvocationHandler create(Target target, Map<Method, MethodHandler> dispatch) {
        return new RouteInvocationHandler(target, dispatch, routeLoadService);
    }
}
